<?php
function add_help_link($title, $url){
    global $help_links;
    array_push($help_links, Array('title' => $title, 'url' => $url));
}

function add_mini_help($name) {
    global $helpHTML;
    require_once 'GUI/Help/helpManager.php';
    $helpHTML = getMiniHelpHTML($name);
    return $helpHTML;
}

/* Html of all messages */
function messages($type){
    global $error_messages;
    global $warning_messages;
    global $success_messages;
    global $other_messages;
    switch($type){
        case 'other':
            return implode(' ', $other_messages);
        case 'error':
            $messages = $error_messages;
            if(count($messages) == 1){
                $title = "Klaida";
            }
            else {
                $title = "Klaidos";
            }
            break;
        case 'warning':
            $messages = $warning_messages;
            if(count($messages) == 1){
                $title = "Perspėjimas";
            }
            else {
                $title = "Perspėjimai";
            }
            break;
        case 'success' :
            $messages = $success_messages;
            $title = "";
            break;
        default: return;
    }
    if(count($messages) == 0){
        return;
    }
    if($title != ''){
        $title = '<div class="msg_title">'.$title.':</div>';
    }
    $content = '<div class="messages '.$type.'">'.$title.'<ul>';
    foreach($messages as $msg){
        $content .= '<li>'.$msg.'</li>';
    }
    $content .= '</ul></div>';
    return $content;
}

/*
 * Apsimąstyt kuris variantas geresnis: tabų ar helpo?
 */

function tabHeader($name, $command, $selected = false) {
    $name = htmlspecialchars($name);
    $command = htmlspecialchars($command);
    if ($selected) {
        return '<div class="active_tab">'.$name.'</div>';
    } else {
        return '<div class="tab"><a href="'.$command.'">'.$name.'</a></div>';
    }
    
}

function form_help_link($link){
    return '<li><a href="#" onclick="window.open(\''.$link['url'].'\',\''.$link['title'].'\',\'width=600,height=300\')">'.$link['title'].'</a></li>';
}
function form_help_widget($help){
    $content = '<div class="menu" id="help_menu"><h2>Pagalba</h2><div class="helpContent">';
    $content .= $help;
    $content .= '</div></div>';
    return $content;
}
?>
